# frozen_string_literal: true

ActiveAdmin.register SchemaVariable do
  menu parent: ['Schema'], priority: 2

  includes :schema, :variable_type
  index do
    id_column
    column 'Name', :name
    column 'Schema' do |variable|
      link_to variable.schema.name, admin_schema_path(variable.schema)
    end
    column 'Type' do |variable|
      link_to variable.variable_type.name, admin_variable_type_path(variable.variable_type)
    end
    column 'IO Type', :io_type
    column 'Required', :required
    column 'Default Value', :default_value
    column :created_at
    column :updated_at

    actions
  end

  filter :schema
  filter :name, filters: %i[equals contains]
  filter :variable_type
  filter :io_type, as: :select, collection: proc { SchemaVariable::IoType.values }
  filter :required, as: :select, collection: proc { [true, false] }

  form do |f|
    f.inputs do
      f.input :schema, input_html: { class: 'select2' }
    end

    f.submit
  end
end
